package com.space.mygql.stitching.namespace.nacos;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.spring.beans.factory.annotation.NamingServiceBeanBuilder;
import com.space.mygql.stitching.namespace.NameSpaceService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @author <a href="mailto:414563035@qq.com">Bedroom</a>
 * @date 2021/5/26 7:01 下午
 */
@Configuration
@ConditionalOnClass(NamingServiceBeanBuilder.class)
public class NacosNameSpaceConfiguration {
    @Resource
    NamingServiceBeanBuilder namingServiceBeanBuilder;

    @Bean
    @ConditionalOnMissingBean
    public NameSpaceService nameSpaceService() throws NacosException {
        return new NacosNameSpaceService(namingServiceBeanBuilder.resolveProperties(new HashMap<>(0)));
    }
}
